/*
 * Copyright 2013 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.wizardpager.wizard.model;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;

import android.graphics.Bitmap;
import android.support.v4.app.Fragment;

import com.example.android.wizardpager.wizard.ui.PictureFragment;

/**
 * A page offering the user a number of non-mutually exclusive choices.
 */
public class PicturePage extends Page {
	
	private String label;
    public PicturePage(ModelCallbacks callbacks, String title) {
        super(callbacks, title);
        label = "";
    }


	@Override
    public Fragment createFragment() {
        return PictureFragment.create(getKey());
    }

    @Override
    public void getReviewItems(ArrayList<ReviewItem> dest) {      

        Bitmap bmp = mData.getParcelable(Page.IMAGE_DATA_KEY);
        if (bmp != null && bmp.getHeight() > 0)
        {
        	dest.add(new ReviewItem(getTitle(), bmp, getKey()));
        }
    }

    @Override
    public boolean isCompleted() {
        Bitmap p = mData.getParcelable(Page.IMAGE_DATA_KEY);
        return p != null && p.getHeight() > 0;
    }

	public String getLabel() {
		return label;
	}
	
	public PicturePage setLabel(String Label) {
		label = Label;
        return this;
    }

	public byte[] getImageBlobData() {
		// TODO Auto-generated method stub
		Bitmap bmp = mData.getParcelable(Page.IMAGE_DATA_KEY);
		if (null != bmp) 
		{
			ByteArrayOutputStream stream = new ByteArrayOutputStream();
			bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
			return stream.toByteArray();
		}
		return null;
	}
	
	public void setImageBlobData(Bitmap bmp) {
		mData.putParcelable(Page.IMAGE_DATA_KEY,bmp);
	}
	
}
